import {ADD_COUNTER, ADDTOCART} from './mutains-types'

export default {
  addCart(context, payload){
    return new Promise((resovele) => {
      //1.查找之前的数组中是否存在该商品
      let oldProduct = context.state.cartList.find(item => item.iid === payload.iid);
      //判断oldPriduct是否为true,true商品数目加一，flase新增对象
      if (oldProduct) {
        context.commit(ADD_COUNTER, oldProduct);
        resovele('当前商品数量+1')
      }else{
        payload.count =1;
        context.commit(ADDTOCART, payload);
        resovele('添加新的商品')
      }
    })
    
  }
}